package client.comm.baoding.dialog

import android.content.Context
import androidx.databinding.ObservableField
import client.comm.baoding.R
import client.comm.baoding.databinding.LayoutZhaimaidialogBinding
import client.comm.commlib.toast.toast
import client.tzstore.oo.dialog.CenterDialog

open class ZhaiMaiDialog(context: Context) : CenterDialog<LayoutZhaimaidialogBinding>(context) {

    var title: String = "摘买"
    var okTxt: String = ""
    var cancleTxt: String = "取消"
    var cancle: (() -> Unit)? = null
    var okPay: ((Int) -> Unit)? = null

    val pwd = ObservableField<String>()
    val showNum = ObservableField<Boolean>(true)
    val num = ObservableField<String>()

    fun okClick(i: Int) {

        if (pwd.get().isNullOrEmpty()) {
            toast("请输入支付密码")
        } else if (showNum.get() == true && num.get().isNullOrEmpty()) {
            toast("请输入份额")
        } else {
            okPay?.invoke(i)
            cancel()
        }
    }

    fun cancleClick() {
        cancle?.apply {
            this()
        }
        cancel()
    }

    override fun getV(): Int {
        return R.layout.layout_zhaimaidialog
    }

    override fun postBinding() {
        binding.event = this
    }
}